<template>
  <!-- <div>订单管理</div> -->
  <div>
    <!-- 面包屑 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片 -->
    <el-card class="box-card">
      <!-- 搜索 -->
      <el-input
        placeholder="请输入内容"
        v-model="searchVal"
        class="input-with-select"
      >
        <el-button slot="append" icon="el-icon-search"></el-button>
      </el-input>
      <!-- 表格 -->
      <el-table :data="OrderData" style="width: 100%" border>
        <el-table-column label="#" type="index"> </el-table-column>
        <el-table-column prop="order_number" label="订单编号" width="580">
        </el-table-column>
        <el-table-column prop="order_price" label="订单价格" width="80">
        </el-table-column>
        <el-table-column prop="pay_status" label="是否付款" width="80">
          <template slot-scope="scope">
            <!-- {{ scope.row }} -->
            <el-tag type="success" v-if="scope.row.pay_status == '1'"
              >已付款</el-tag
            >
            <el-tag type="danger" v-else-if="scope.row.pay_status == '0'"
              >未付款</el-tag
            >
          </template>
        </el-table-column>

        <el-table-column prop="is_send" label="是否发货" width="80">
        </el-table-column
        ><el-table-column prop="create_time" label="下单时间" widht="120px">
          <template slot-scope="scope">
            <!-- 过滤器第一个参数是 穿过去的,第二个是过滤器名字 -->
            {{ scope.row.create_time | DateFilter }}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="mini"
              @click="editAddr"
            ></el-button>
            <el-button
              type="success"
              icon="el-icon-location"
              size="mini"
              @click="viewExpress(scope.row.order_id)"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="orderQuery.pagenum"
        :page-sizes="[5, 10, 50, 100]"
        :page-size="orderQuery.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
      <!-- 编辑订单信息 -->
      <el-dialog
        title="修改地址"
        :visible.sync="editAddrDisplay"
        width="50%"
        @close="closeEditAddr"
      >
        <el-form
          :model="addrDataForm"
          :rules="Addrrules"
          ref="AddrruleForm"
          label-width="100px"
        >
          <el-form-item label="省市区/县" prop="addr1">
            <el-cascader
              v-model="addrDataForm.addr1"
              :options="getAddr"
              :props="{ expandTrigger: 'hover' }"
            ></el-cascader>
          </el-form-item>
          <el-form-item label="详细信息" prop="addr2">
            <el-input v-model="addrDataForm.addr2"></el-input>
          </el-form-item>
        </el-form>

        <span slot="footer" class="dialog-footer">
          <el-button @click="editAddrDisplay = false">取 消</el-button>
          <el-button type="primary" @click="editAddrDisplay = false"
            >确 定</el-button
          >
        </span>
      </el-dialog>
      <!-- 查看物流 -->
      <el-dialog title="物流进度" :visible.sync="ExpressDisplay" width="50%">
        <!-- 时间线 -->
        <el-timeline :reverse="reverse">
          <el-timeline-item
            v-for="(Express, index) in ExpressInfo"
            :key="index"
            :timestamp="Express.time"
          >
            {{ Express.context }}
          </el-timeline-item>
        </el-timeline>
      </el-dialog>
    </el-card>
  </div>
</template>

<script>
import cityData from "./citydata.js";
export default {
  data() {
    return {
      searchVal: "",
      // 订单数据参数
      orderQuery: {
        // 当前页码
        pagenum: 1,
        // 每页显示条数
        pagesize: 10
      },
      // 订单数据列表
      OrderData: [],
      total: 0,
      editAddrDisplay: false,
      ExpressDisplay: false,
      // 编辑地址表单验证规则
      Addrrules: {
        addr1: [{ required: true, message: "请选择", trigger: "blur" }],
        addr2: [
          { required: true, message: "请填写详细信息地址", trigger: "blur" }
        ]
      },
      // 编辑地址数据对象
      addrDataForm: {
        addr1: "",
        addr2: ""
      },
      // 获取下拉框选择地址的数据
      getAddr: cityData,
      reverse: true,
      ExpressInfo: []
    };
  },
  created() {
    this.orderData();
  },
  methods: {
    orderData() {
      // console.log("请求订单数据");
      this.$http
        .get("/orders", { params: this.orderQuery })
        .then(ret => {
          if (ret.data.meta.status !== 200) {
            return this.$message.error("获取订单数据失败!");
          }
          this.OrderData = ret.data.data.goods;
          this.total = ret.data.data.total;
        })
        .catch(err => {
          console.log(err);
        });
    },
    // 编辑/修改地址
    editAddr() {
      this.editAddrDisplay = true;
    },
    // 分页函数
    handleSizeChange(current) {
      this.orderQuery.pagesize = current;
      this.orderData();
    },
    handleCurrentChange(current) {
      this.orderQuery.pagenum = current;
      this.orderData();
    },
    // 点击查看物流
    async viewExpress(id) {
      this.ExpressDisplay = true;
      // const { data: ret } = await this.$http.get(`/kuaidi/${id}`);
      this.ExpressInfo = [
        {
          time: "2018-05-10 09:39:00",
          ftime: "2018-05-10 09:39:00",
          context: "已签收,感谢使用顺丰,期待再次为您服务",
          location: ""
        },
        {
          time: "2018-05-10 08:23:00",
          ftime: "2018-05-10 08:23:00",
          context:
            "[北京市]北京海淀育新小区营业点派件员 顺丰速运 95338正在为您派件",
          location: ""
        },
        {
          time: "2018-05-10 07:32:00",
          ftime: "2018-05-10 07:32:00",
          context: "快件到达 [北京海淀育新小区营业点]",
          location: ""
        },
        {
          time: "2018-05-10 02:03:00",
          ftime: "2018-05-10 02:03:00",
          context:
            "快件在[北京顺义集散中心]已装车,准备发往 [北京海淀育新小区营业点]",
          location: ""
        },
        {
          time: "2018-05-09 23:05:00",
          ftime: "2018-05-09 23:05:00",
          context: "快件到达 [北京顺义集散中心]",
          location: ""
        },
        {
          time: "2018-05-09 21:21:00",
          ftime: "2018-05-09 21:21:00",
          context: "快件在[北京宝胜营业点]已装车,准备发往 [北京顺义集散中心]",
          location: ""
        },
        {
          time: "2018-05-09 13:07:00",
          ftime: "2018-05-09 13:07:00",
          context: "顺丰速运 已收取快件",
          location: ""
        },
        {
          time: "2018-05-09 12:25:03",
          ftime: "2018-05-09 12:25:03",
          context: "卖家发货",
          location: ""
        },
        {
          time: "2018-05-09 12:22:24",
          ftime: "2018-05-09 12:22:24",
          context: "您的订单将由HLA（北京海淀区清河中街店）门店安排发货。",
          location: ""
        },
        {
          time: "2018-05-08 21:36:04",
          ftime: "2018-05-08 21:36:04",
          context: "商品已经下单",
          location: ""
        }
      ];
    },
    // 关闭修改地址的回调
    closeEditAddr() {
      this.$refs.AddrruleForm.resetFields();
    }
  }
  // filter: {}
};
</script>

<style lang="less" scoped>
.el-card {
  user-select: none;
  .el-input {
    width: 398px;
  }
  .el-pagination {
    margin-top: 20px;
  }
  .el-cascader,
  .el-dialog .el-input {
    width: 100%;
  }
  .el-timeline {
    // padding:
    padding-left: 50px;
  }
}
</style>
